package com.wlc.controller;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wlc.dto.StudentsAndProductDto;
import com.wlc.entity.Product;
import com.wlc.entity.StudentScore;
import com.wlc.service.ProductService;
import com.wlc.service.ThirdService;
import com.wlc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    ProductService productService;

    @Autowired
    UserService userService;
    @Autowired
    ThirdService thirdService;

    @GetMapping("/getOrderInfo")
    public String getOrderInfo() {
        String dataFromThirdParty = thirdService.getDataFromThirdParty();
        return dataFromThirdParty;
    }

    @GetMapping("/getStudentAndProduct/{studentName}/{productId}")
    public StudentsAndProductDto getStudentAndProduct(@PathVariable(value = "studentName") String studentName, @PathVariable(value = "productId") Integer productId) {
        StudentsAndProductDto studentsAndProductDto = userService.getStudentAndProduct(studentName, productId);
        String jsonString = JSON.toJSONString(studentsAndProductDto);
        System.out.println("jsonString = " + jsonString);
        return studentsAndProductDto;
    }

    @GetMapping("/hello")
    public Product test() {
        Product product = productService.getProduct(1);
        System.out.println("product.getProductName() = " + product.getProductName());
        return product;
    }

    /**
     * mybatis-plus 测试
     *
     * @return
     */
    @GetMapping("/hello2")
    public StudentScore getProduct() {
        StudentScore studentScore = userService.getUserByName("张三1");
        System.out.println("product.getProductName() = " + JSON.toJSONString(studentScore));
        return studentScore;
    }

    @PostMapping("/getUserPage")
    public IPage<StudentScore> getUserPage(@RequestParam(value = "currentPage") int currentPage, @RequestParam(value = "pageSize") int pageSize) {
        IPage<StudentScore> userIPage = userService.queryUserPage(currentPage, pageSize);
        return userIPage;
    }
}
